package java04woid;

import java.util.ArrayList;
import java.util.Scanner;

public class data {
    public static void main(String[] args) {

        //创建集合
        ArrayList<Dataclass> array = new ArrayList<>();
        while(true){
            System.out.println("---------------------学生管理系统----------------------");
            System.out.println("1添加同学，2删除同学，3修改同学，4查看同学，5查找同学，6退出系统");
            System.out.println("-----------------------------------------------------");
            Scanner num =new Scanner(System.in);
            int nums =num.nextInt();
            System.out.println("-----------------------------------------------------");
            switch (nums){
                case 1:
                    increase(array);
                    break;
                case 2:
                    delete(array);
                    break;
                case 3:
                    revise(array);
                    break;
                case 4:
                    View(array);
                    break;
                case 5:
                    look(array);
                    break;
                case 6:
                    System.exit(0);
                    break;
            }
        }


    }
    //添加
    public static void increase(ArrayList<Dataclass> array) {
        Scanner sc =new Scanner(System.in);
        System.out.println("--------------请输入姓名--------------");
        String x = sc.next();
        System.out.println("--------------请输入年龄--------------");
        int y = sc.nextInt();
        System.out.println("--------------请输入学号--------------");
        int z = sc.nextInt();

        //创建对象
        Dataclass obj = new Dataclass();
        obj.name = x;
        obj.age = y;
        obj.id = z;

        array.add(obj);
        //信息添加成功提示
        System.out.println("添加学生信息成功");
    }

    //删除
    public static void delete(ArrayList<Dataclass> array) {
        Scanner sc =new Scanner(System.in);
        System.out.println("--------------请输入学号--------------");
        int x = sc.nextInt();

        for (int i = 0; i < array.size(); i++) {
            if (array.get(i).id == x){
                array.remove(i);
                System.out.println("删除学生信息成功");
            }
        }

    }

    //修改
    public static void revise(ArrayList<Dataclass> array) {
        Scanner sc =new Scanner(System.in);
        System.out.println("--------------请输入学号--------------");
        int xx = sc.nextInt();
        int xb = 0;
        for (int i = 0; i < array.size(); i++) {
            if (array.get(i).id == xx){
                xb = i;
            }
        }
        Scanner scxg =new Scanner(System.in);
        System.out.println("--------------请输入姓名--------------");
        String x = scxg.next();
        System.out.println("--------------请输入年龄--------------");
        int y = scxg.nextInt();

        //创建对象
        Dataclass obj = new Dataclass();
        obj.name = x;
        obj.age = y;
        obj.id = xx;

        array.set(xb,obj);
        System.out.println("修改学生信息成功");
    }

    //查看
    public static void View(ArrayList<Dataclass> array) {
        for (int i = 0; i < array.size(); i++) {
            System.out.println("姓名："+array.get(i).name+"   年龄："+array.get(i).age+"   学号："+array.get(i).id);
        }
    }

    //查找
    public static void look(ArrayList<Dataclass> array) {
        Scanner sc =new Scanner(System.in);
        System.out.println("--------------请输入学号--------------");
        int xx = sc.nextInt();
        int xb = 0;
        for (int i = 0; i < array.size(); i++) {
            if (array.get(i).id == xx){
                xb = i;
            }
        }
        System.out.println("姓名："+array.get(xb).name+"   年龄："+array.get(xb).age+"   学号："+array.get(xb).id);
    }
}
